package com.principles.create.prototype;
/**
 * @Description  原型模式：
 * 可以快速的生成克隆体，克隆体不需要执行初始化代码，节约了创建时间
 *
 * @Date 2025/1/29 23:57
 **/
public class PrototypePattern {
    public static void main(String[] args) {
        Plane plane = new Plane();
        System.out.println(plane.getName()+" "+plane.getType());
        Plane clone =(Plane) plane.clone();
        System.out.println(clone.getName()+" "+clone.getType());

    }
}
// 原型接口
interface Prototype{
    Object clone();
}
// 飞机类
class Plane implements Prototype{
    private String name;
    private String type;
    public Plane(){
        name = "Name"+Math.random();
        type = "Type"+Math.random();
    }

    public Plane(Plane plane) {
        this.name = plane.name;
        this.type = plane.type;
    }

    public String getName() {
        return name;
    }

    public String getType() {
        return type;
    }

    @Override
    public Object clone() {
        return new Plane(this);
    }
}